
/*

Design Pattern Automation Toolkit.
Application to create applications with emphasis on Design patterns.
And support for round trip engineering.
Copyright (C) 2004 Vineeth Neelakant. nvineeth@gmail.com

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/
using System;using BusinessLayer;using InfoClasses;using dpatoolkit.UILayer;
using DesignPatternDefinitions;
using System.Data;
using System.Collections;
using System.Windows.Forms;
using System.Drawing;
namespace BusinessLayer
{
	/// <summary>
	/// class that implements IClass
	/// </summary>
	public class DPClass : IClass
	{
		private string compName,cName;
		private DataSet dataset;
		private DataTable clsTable;
		private DataRow clsRow;
		MetaInfoEditor mie ;
		public DPClass(string comp,string cls,DataSet ds)
		{
			this.compName=comp;
			this.cName=cls;
			this.dataset=ds;
			this.clsTable=ds.Tables[SchemaNames.Classes];
			this.clsRow = this.clsTable.Rows.Find(new object[]
				{this.compName,this.cName}
				);
			mie = new MetaInfoEditor((string)this.clsRow[SchemaNames.MetaInfo]);
		}

		#region IClass Members

		public System.Collections.ArrayList Methods
		{
			get
			{
				//first find the methods that belong to this class :)
				ArrayList methodList = new ArrayList();
				DataTable methodTable = this.dataset.Tables[SchemaNames.Methods];
				DataRow []rows = methodTable.Select(SchemaNames.ComponentName+"='"+this.compName+"' and "+
					SchemaNames.ClassName+"='"+this.cName+"'",SchemaNames.MethodVisibility);
				foreach( DataRow row in rows)
				{
					methodList.Add( new DPMethod(this.compName,this.cName,
						(int)row[SchemaNames.MethodID],row));
				}
				
				return methodList;
				
			}
			set
			{
				// TODO:  Add DPClass.Methods setter implementation
			}
		}

		public System.Collections.ArrayList SingleReferences
		{
			get
			{
				// TODO:  Add DPClass.SingleReferences getter implementation
				return null;
			}
			set
			{
				// TODO:  Add DPClass.SingleReferences setter implementation
			}
		}

		public System.Collections.ArrayList InheritedClasses
		{
			get
			{
				ArrayList inhList = new ArrayList();
				DataRow [] irows= this.dataset.Tables[SchemaNames.Inheritances].Select(
					 SchemaNames.DerivedClassComponent+"='"+ this.compName+"' and " + 
					SchemaNames.DerivedClass+"='"+this.cName+"'");
				foreach (DataRow row in irows )
				{
					inhList.Add( new DPInheritance(row));
				}
				return inhList;
			}
			set
			{
				// TODO:  Add DPClass.InheritedClasses setter implementation
			}
		}

		public ClassType ClassType
		{
			get
			{
				string s = (string) this.clsRow[SchemaNames.ClassType];
				if(s==ClassType.Concrete.ToString().ToLower()) return ClassType.Concrete;
				return ClassType.Abstract;
				
			}
			set
			{
				// TODO:  Add DPClass.ClassType setter implementation
			}
		}
		

		public string QualifiedClassName
		{
			get
			{
				// TODO:  Add DPClass.QualifiedClassName getter implementation
				return null;
			}
			set
			{
				// TODO:  Add DPClass.QualifiedClassName setter implementation
			}
		}

		public System.Collections.ArrayList MultiReferences
		{
			get
			{
				// TODO:  Add DPClass.MultiReferences getter implementation
				return null;
			}
			set
			{
				// TODO:  Add DPClass.MultiReferences setter implementation
			}
		}

		public string ClassSummary
		{
			get
			{
				return (string) this.clsRow[SchemaNames.Summary];
			}
			set
			{
				this.clsRow[SchemaNames.Summary]=(string)value;
			}
		}

		public string AccessModifier
		{
			get
			{
				// TODO:  Add DPClass.AccessModifier getter implementation
				return null;
			}
			set
			{
				// TODO:  Add DPClass.AccessModifier setter implementation
			}
		}

		public System.Collections.ArrayList Fields
		{
			get
			{
				ArrayList fldList = new ArrayList();
				//first find the rows which contain the fileds
				DataTable fldTable = this.dataset.Tables[SchemaNames.Fields];
				DataRow []rows = fldTable.Select(SchemaNames.ComponentName+"='"+this.compName+"' and "+
					SchemaNames.ClassName+"='"+this.cName+"'",SchemaNames.Visibility);
				foreach( DataRow row in rows)
				{
					fldList.Add( new DPField(this.compName,this.cName,
						(string)row[SchemaNames.FieldName],row));
				}
				
				return fldList;
			}
			set
			{
				// TODO:  Add DPClass.Fields setter implementation
			}
		}

		public string ClassName
		{
			get
			{
				return this.cName;
			}
			set
			{
				// TODO:  Add DPClass.ClassName setter implementation
			}
		}

		public string ComponentName
		{
			get
			{
				return this.compName;
			}
			set
			{
				
			}
		}

		public bool Abstract
		{
			get
			{
				string s = (string) this.clsRow[SchemaNames.ClassType];
				if(s==DesignPatternDefinitions.ClassType.Concrete.ToString().ToLower()) return false;
				return true;
			}
			set
			{
				// TODO:  Add DPClass.Abstract setter implementation
			}
		}

		public ArrayList Aggregates
		{
			get
			{
				ArrayList aggList = new ArrayList();
				DataRow [] arows= this.dataset.Tables[SchemaNames.Aggregates].Select(
					SchemaNames.AggregatorClassComponent+"='"+ this.compName+"' and " + 
					SchemaNames.AggregatorClass+"='"+this.cName+"'");
				foreach (DataRow row in arows )
				{
					aggList.Add( new DPAggregate(row));
				}
				return aggList;

			}
			set
			{
			}
		}
		public ArrayList References
		{
			get
			{
				ArrayList refList = new ArrayList();
				DataRow [] arows= this.dataset.Tables[SchemaNames.References].Select(
					SchemaNames.ReferenceComponent+"='"+ this.compName+"' and " + 
					SchemaNames.ReferenceClass+"='"+this.cName+"'");
				foreach (DataRow row in arows )
				{
					refList.Add( new DPReference(row));
				}
				return refList;
			}
			set{}
		}
		public ArrayList Creations
		{
			get
			{
				ArrayList list = new ArrayList();
				DataRow [] arows= this.dataset.Tables[SchemaNames.Creates].Select(
					SchemaNames.CreatorComponentName+"='"+ this.compName+"' and " + 
					SchemaNames.CreatorClassName+"='"+this.cName+"'");
				foreach (DataRow row in arows )
				{
					
					list.Add( new DPCreation(row));
				}
				return list;
			}
			set{}
		}

		public Point UILocation
		{
			get
			{
				DataTable uitable = this.dataset.Tables[SchemaNames.UIDetails];
				DataRow[] row = uitable.Select(SchemaNames.ComponentName+"='"+ this.compName+"' and " +
					SchemaNames.ClassName+"='"+this.cName+"'");
				if( row.Length!=1)
				{
					
					Console.WriteLine("Error while getting UILocation:"+this.cName + "--" +  this.compName,"Error");
					return new Point(-1,-1) ;
				}
				Point p = new Point(0,0);
				p.X= (int) row[0][SchemaNames.XCoOrdinate];
				p.Y= (int) row[0][SchemaNames.YCoOrdinate];
				return p;
				}
			set{}
		}

		public string GetMetaInfo(string language)
		{
			return mie.GetMetaInfo(language);
		}
		
		public Hashtable GetAllMetaInfo()
		{
			return mie.GetAllMetaInfo();
		}
		#endregion
	}
}
